<template>
	<view class="default-show" v-if="!defaultShow">
		<image class="mask-img" src="../../static/d.jpg" mode=""></image>
		<view class="footer-authorization">
			<view class="footer-btn">
				<button class="btn-style" @click="showErrToast('请先勾选用户协议')" v-if="!agree">授权登录</button>
				<button class="btn-style is-agree" id="agree-btn" open-type="getPhoneNumber|agreePrivacyAuthorization"
					@getphonenumber="getPhoneNumber" @agreeprivacyauthorization="handleAgree" v-else>授权登录</button>
				<button class="btn-style is-disagree" id="disagree-btn" @click="handleDisagree">暂不登录</button>
			</view>
			<view class="button-box" @click="agree=!agree">
				<view>
					<checkbox-group>
						<checkbox :checked="agree" style="transform:scale(0.8) ;" />
					</checkbox-group>
					<view class="text" style="font-size: 24upx;color: #909399;bottom: 50upx;">
						您已阅读并同意
						<text @click.stop="toagreement" style="color: #007AFF;">《用户服务协议》</text>
						<text @click.stop="openPrivacyContract" style="color: #007AFF;">，《隐私协议》</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var WXBizDataCrypt = require('@/utils/RdWXBizDataCrypt.js');
	export default {
		data() {
			return {
				defaultShow: false,
				appId: getApp().globalData.appId,
				sessionkey: uni.getStorageSync('sk'),
				wxOpenId: uni.getStorageSync('openId'),
				isNiuniu: false,
				isGZH: false,
				agree: false,

				// 隐私指引弹框
				showPrivacyMask: false,
				title: '用户隐私保护提示',
				desc: '在使用当前小程序服务前，请仔细阅读',
				protocol: '《用户隐私保护指引》',
				subDesc: '。如您同意，请点击【同意】开始使用',
			}
		},
		onLoad(e) {
			this.init(e)
		},
		methods: {
			init(e) {
				if (e.isNiuniu == 1) {
					this.isNiuniu = true
				}
				if (e.isGZH == 1) {
					this.isGZH = true
				}
			},
			openPrivacyContract() {
				wx.openPrivacyContract()
			},
			handleDisagree() {
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
			handleAgree() {
				this.showPrivacyMask = false
			},
			toagreement() {
				uni.navigateTo({
					url: '/pages/agreement/agreement'
				})
			},
			showErrToast(title) {
				uni.showToast({
					icon: 'none',
					title: title
				})
			},
			getPhoneNumber(e) {
				if (e.detail.errMsg == "getPhoneNumber:fail user deny") { //用户决绝授权  
				} else {
					uni.showLoading()
					var pc = new WXBizDataCrypt(this.appId, this.sessionkey);
					var data = pc.decryptData(e.detail.encryptedData, e.detail.iv)
					this.$http('/minprogram/api/member/bind', {
						"wxOpenId": this.wxOpenId,
						"phone": data.phoneNumber,
						"wxName": data.phoneNumber,
						"pubOpenId": uni.getStorageSync('pubopenid') || ''
					}, res => {
						uni.setStorageSync('token', res.data.token)
						if (this.isNiuniu) {
							if (this.isGZH) {
								uni.reLaunch({
									url: '/pages/niuniuIndex/niuniuIndex?type=2'
								})
							} else {
								uni.reLaunch({
									url: '/pages/shopMall/shopMall'
								})
							}
						} else {
							uni.reLaunch({
								url: `/pages/index/index?type=2&phone=${data.phoneNumber}`
							})
						}
					})
				}
			},
			goBack() {
				uni.navigateBack()
			},
			toagreement() {
				uni.navigateTo({
					url: '/pages/agreement/agreement'
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.default-show {
		width: 100vw;
		height: 100vh;
		.mask-img {
			width: 100%;
			height: 100%;
		}
	}
	.footer-authorization{
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		background: #fff;
		box-shadow: 0 -8upx 16upx rgba(0, 0, 0, 0.2);
		padding-top: 86upx;
		.footer-btn{
			// display: flex;
			// align-items: center;
			// justify-content: space-between;
			.btn-style{
				// width: 298upx;
				width: 690upx;
				height: 80upx;
				border-radius: 10upx;
				font-size: 28upx;
				text-align: center;
				line-height: 80upx;
				background: #49b9ad;
				color: #fff;
			}
			.is-disagree{
				background: #e4e4e4;
				margin-top: 56upx;
				color: #6a6a6a;
			}
		}
	}
	.button-box {
		width: 700upx;
		margin: 32upx auto 120upx;
		border-radius: 20upx;
		box-sizing: border-box;
		padding: 26upx 0;
		>view {
			font-size: 26upx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
		}
	}
</style>